package com.smartscreen.grademanage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartscreen.grademanage.entity.Score;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ScoreMapper extends BaseMapper<Score> {
    
    @Select("SELECT s.* " +
            "FROM score s " +
            "LEFT JOIN exam e ON s.exam_id = e.id " +
            "WHERE s.student_id = #{studentId} " +
            "AND (#{termId} IS NULL OR e.term_id = #{termId}) " +
            "AND (#{examId} IS NULL OR s.exam_id = #{examId})")
    List<Score> getStudentScores(@Param("studentId") String studentId, 
                                @Param("termId") String termId, 
                                @Param("examId") String examId);
    
    // 移除了对student表的直接查询，改为通过学生ID列表查询成绩
    @Select("SELECT s.* " +
            "FROM score s " +
            "WHERE s.exam_id = #{examId} " +
            "AND s.student_id IN (#{studentIds})")
    List<Score> getClassScores(@Param("examId") String examId, 
                              @Param("studentIds") List<String> studentIds);
    
    // 根据学生ID列表获取成绩（与getClassScores功能相同，可以合并）
    @Select("SELECT s.* " +
            "FROM score s " +
            "WHERE s.exam_id = #{examId} " +
            "AND s.student_id IN (#{studentIds})")
    List<Score> getScoresByStudentIds(@Param("examId") String examId, 
                                     @Param("studentIds") List<String> studentIds);
}